package com.dc.project_java.test.news;

import androidx.lifecycle.MutableLiveData;

import com.dc.base.network.RequestCallback;
import com.dc.base.viewmodel.BaseViewModel;

import io.reactivex.disposables.Disposable;

public class NewsViewModel extends BaseViewModel {

    private MutableLiveData<NewsBean> newsLiveData = new MutableLiveData<>();

    private NewsRepository mNewsRepository = new NewsRepository();

    public void requestData() {
        loadingDialogLiveData.setValue(true, "加载中");
        Disposable disposable = mNewsRepository.getNews(new RequestCallback<NewsBean>() {
            @Override
            public void onSuccess(NewsBean newsBean) {
                loadingDialogLiveData.setValue(false);
                newsLiveData.setValue(newsBean);
            }

            @Override
            public void onFailure(int code, String errorMsg) {
                loadingDialogLiveData.setValue(false);
            }
        });
        addDisposable(disposable);
    }

    public MutableLiveData<NewsBean> getNewsLiveData() {
        return newsLiveData;
    }
}
